package Pages;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.util.Map;

import static Driver.DriverSingleton.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class LoginPageAgg {

    WebDriver driver = getChromeDriver();
    Map<String,Object> vars = getVars();

    //进入网页
    public LoginPageAgg goLoginPage(){
        driver.get("https://sei-test.021hqit.com/group-6/");
        assertThat(driver.getTitle(), is("登录"));
        driver.manage().window().setSize(new Dimension(885, 770));
        return this;
    }

    public LoginPageAgg login(String userId, String password){
        //输入用户名
        driver.findElement(By.cssSelector(".el-form-item:nth-child(1) .el-input__inner")).click();
        driver.findElement(By.cssSelector(".el-form-item:nth-child(1) .el-input__inner")).sendKeys(userId);
        //输入密码
        driver.findElement(By.cssSelector(".el-form-item:nth-child(2) .el-input__inner")).click();
        driver.findElement(By.cssSelector(".el-form-item:nth-child(2) .el-input__inner")).sendKeys(password);
        //按下登录键
        driver.findElement(By.cssSelector(".el-button")).click();
        return this;
    }


    public String getMessage(){
        //弹出消息提示
        waitForWindow(2000);
        WebElement elementText = driver.findElement(By.cssSelector("div.el-message"));
        String info = elementText.getText();
        return info;
    }

    public String getLoginInputErrorMessage1(){
        waitForWindow(2000);
        WebElement elementText = driver.findElement(By.cssSelector(".el-form-item:nth-child(1) .el-form-item__error"));
        String info = elementText.getText();
        return info;
    }

    public String getLoginInputErrorMessage2(){
        waitForWindow(2000);
        WebElement elementText = driver.findElement(By.cssSelector(".el-form-item:nth-child(2) .el-form-item__error"));
        String info = elementText.getText();
        return info;
    }

    public LoginPageAgg toHomePage(){
        waitForWindow(2000);
        assertThat(driver.getTitle(), is("首页"));
        return this;
    }



}
